//
//  DetailTableViewCell.m
//  HQJFacilitator
//
//  Created by mymac on 2016/10/2.
//  Copyright © 2016年 Fujian first time iot technology investment co., LTD. All rights reserved.
//

#import "DetailTableViewCell.h"
@interface DetailTableViewCell()
@property (nonatomic,strong)UILabel *bonusLable;
@property (nonatomic,strong)UILabel *timerLabel;
@property (nonatomic,strong)UILabel *typeLabel;
@end
@implementation DetailTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
//        [self createUI];
    }
    
    
    return self;
    
    
}
-(UIImageView *)TitleImageView {
    
    if (!_TitleImageView) {
        _TitleImageView = [[UIImageView alloc]init];
        
        _TitleImageView.backgroundColor = [UIColor redColor];
        _TitleImageView.layer.cornerRadius = 20;
        _TitleImageView.layer.masksToBounds = YES;
        
        [self addSubview:_TitleImageView];
        
    }
    
    
    
    
    return _TitleImageView;
}
-(UILabel *)bonusLable {
    if (!_bonusLable) {
        _bonusLable  = [[UILabel alloc]init];
        _bonusLable.textColor = [ManagerEngine getColor:@"00c2ae"];
//        _bonusLable.backgroundColor = [ManagerEngine getColor:@"00c2ae"];
        _bonusLable.font = [UIFont systemFontOfSize:18];
        
        [self addSubview:_bonusLable];
    }
    
    
    
    
    return _bonusLable;
}
-(UILabel *)timerLabel {
    if (!_timerLabel) {
        _timerLabel = [[UILabel alloc]init];
        _timerLabel.textColor = [ManagerEngine getColor:@"999999"];
        _timerLabel.font = [UIFont systemFontOfSize:14];
//        _timerLabel.backgroundColor = [UIColor greenColor];
        [self addSubview:_timerLabel];
    }
    
    
    return _timerLabel;
}
-(UILabel *)typeLabel {
    
    if (!_typeLabel) {
        _typeLabel =[[UILabel alloc]init];
        
      
        
        [self addSubview:_typeLabel];
    }
    
    
    
    return _typeLabel;
}
-(void)createUI {
//    
///*********cell两边的间隔***********/
//    CGFloat spacingCell = 15*2;
//    /*********控件之间的间隔***********/
//    CGFloat spacingView = 5;
//    
////    /*********cell 高度***********/
//    CGFloat CellHight = 70;
////
////    /*********cell两边的间隔***********/
//    
//    
//    self.TitleImageView.sd_layout.leftSpaceToView(self,15).topSpaceToView(self,15).heightIs(CellHight-spacingCell).widthIs(CellHight-spacingCell);
//    
//    self.bonusLable.sd_layout.leftSpaceToView(self.TitleImageView,5).topEqualToView(self.TitleImageView).heightIs(20).widthIs(WIDTH-spacingCell-(CellHight-spacingCell)-5*2-14*4);
//    
//    self.timerLabel.sd_layout.leftEqualToView(self.bonusLable).topSpaceToView(self.bonusLable,0).heightIs(20).widthRatioToView(self.bonusLable,1);
//    
//    self.typeLabel.sd_layout.leftSpaceToView(self.bonusLable,5).topEqualToView(self.bonusLable).heightIs(20).widthIs(4*14);
    
    
}

-(void)updateLayout {
    [super updateLayout];
    CGFloat bonusSize = [ManagerEngine setTextWidthStr:self.bonusLable.text andFont:[UIFont systemFontOfSize:18]];
//        self.bonusLable.sd_layout.leftSpaceToView(self.TitleImageView,5).topEqualToView(self.TitleImageView).heightIs(20).widthIs();
    CGFloat timerSize = [ManagerEngine setTextWidthStr:self.timerLabel.text andFont:[UIFont systemFontOfSize:14]];

    /*********cell两边的间隔***********/
    CGFloat spacingCell = 15*2;
    /*********控件之间的间隔***********/
//    CGFloat spacingView = 5;
    
    //    /*********cell 高度***********/
    CGFloat CellHight = 70;
    //
    //    /*********cell两边的间隔***********/
    
    
    self.TitleImageView.sd_layout.leftSpaceToView(self,15).topSpaceToView(self,15).heightIs(CellHight-spacingCell).widthIs(CellHight-spacingCell);
    
    self.bonusLable.sd_layout.leftSpaceToView(self.TitleImageView,5).topEqualToView(self.TitleImageView).heightIs(20).widthIs(bonusSize);
    
    self.timerLabel.sd_layout.leftEqualToView(self.bonusLable).topSpaceToView(self.bonusLable,0).heightIs(20).widthIs(timerSize);
    
    if (_isCashList == NO) {
        CGFloat typeWidthSize = [self typeWidth];

        self.typeLabel.font = [UIFont systemFontOfSize:14];
        
        self.typeLabel.textColor = [ManagerEngine getColor:@"999999"];
       
        self.typeLabel.sd_layout.leftSpaceToView(self,WIDTH - 15 - typeWidthSize).topEqualToView(self.bonusLable).heightIs(20).widthIs(typeWidthSize);
    } else {
        CGFloat typeSize = [ManagerEngine setTextWidthStr:self.typeLabel.text andFont:[UIFont systemFontOfSize:18]];

        self.typeLabel.font = [UIFont systemFontOfSize:18];
        
        self.typeLabel.textColor = [ManagerEngine getColor:@"f54949"];
        self.typeLabel.sd_layout.leftSpaceToView(self.bonusLable,5).topEqualToView(self.bonusLable).heightIs(20).widthIs(typeSize);
    }
    
    
}


-(void)setCellModel:(DerailModel *)cellModel {
    
    
    
    
    _cellModel = cellModel;    
    
    
    
    if (_isCashList == NO) {
        self.typeLabel.text = cellModel.tradetype;
        
        self.bonusLable.text = [NSString stringWithFormat:@"%@积分",cellModel.amount];
        
        
        self.timerLabel.text = cellModel.tradetime;
        
    } else {
        self.bonusLable.text = [NSString stringWithFormat:@"%.2f积分",[cellModel.amount floatValue]];
        
        
        self.timerLabel.text = cellModel.tradetime;
        self.typeLabel.text = [NSString stringWithFormat:@"(%.2f元)",[cellModel.famount floatValue]];
;

    }
    
    

}


#pragma mark --
#pragma mark --- 交易类型的宽度
-(CGFloat)typeWidth {
    
     CGFloat typeSize = [ManagerEngine setTextWidthStr:self.typeLabel.text andFont:[UIFont systemFontOfSize:14.0]];
    
    return typeSize >= WIDTH /2  ? 100.0 : typeSize;
    
    
}


- (void)awakeFromNib {
    [super awakeFromNib];

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}




@end
